<?php

namespace App\Miya\UIData;

use App\Miya\Models\Blogroll;
use Illuminate\Database\Eloquent\Collection;

class BlogrollData extends CommonData
{
    protected $name = 'blogroll';
    protected $fields = ['id', 'name', 'avatar', 'url'];

    /**
     * 获取友链信息列表
     * @operate  遍历后调用
     *
     * @data id 友链id
     * @data name 友链名称
     * @data avatar 友链图片/Logo
     * @data url 友链超链接
     */
    public function list(): Collection
    {
        return $this->dataCache(function () {
            return Blogroll::select($this->fields)->withoutGlobalScope('id')
                ->orderBy('rank', 'DESC')->get()->map(function ($model) {
                    $model->avatar = asset('uploads/' . $model->avatar);

                    return $model;
                });
        }, __METHOD__);
    }
}
